from django.shortcuts import render
from rest_framework.viewsets import ViewSet, GenericViewSet

from home import models
from home import serializers
from utils.responses import CommonResponse


class GateView(ViewSet):

    def get_gate(self, request):
        gate_mol = models.Gate.objects.filter(is_using=True).first()
        return_data = {
            'sketch': gate_mol.sketch,
            'left_url': 'media/' + str(gate_mol.left),
            'right_url': 'media/' + str(gate_mol.right),
            'left_b_url': 'media/' + str(gate_mol.left_b),
            'right_b_url': 'media/' + str(gate_mol.right_b),
        }
        return CommonResponse(tip='主页入口图片', data=return_data)


class BgView(GenericViewSet):
    queryset = models.BackGround.objects.filter(order__lte=3).order_by('order')
    serializer_class = serializers.BgSerializer

    def get_bg(self, request):
        bg_list = self.get_queryset()
        bg_ser = self.get_serializer(instance=bg_list, many=True)
        return CommonResponse(data=bg_ser.data, tip='主页背景图片')
